<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>智能汽车控制系统</title>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
    <style>
        :root {
            --primary-color: #4361ee;
            --secondary-color: #3f37c9;
            --accent-color: #4895ef;
            --danger-color: #f72585;
            --success-color: #4cc9f0;
            --warning-color: #ffaa00;
            --dark-color: #1a1a2e;
            --light-color: #f8f9fa;
            --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            --transition: all 0.3s ease;
            --map-bg: rgba(26, 26, 46, 0.65);
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'Roboto', 'Microsoft YaHei', sans-serif;
            background: linear-gradient(rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0.85)),
                url('https://images.unsplash.com/photo-1492144534655-ae79c964c9d7?ixlib=rb-1.2.1&auto=format&fit=crop&w=1920&q=80') no-repeat center center fixed;
            background-size: cover;
            color: var(--light-color);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            overflow-x: hidden;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
        }

        /* 登录界面 */
        .login-container {
            max-width: 400px;
            margin: 10% auto;
            padding: 40px;
            background: rgba(26, 26, 46, 0.95);
            border-radius: 15px;
            box-shadow: var(--shadow);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.15);
            animation: fadeIn 0.5s ease-in-out;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .login-container h1 {
            color: var(--accent-color);
            text-align: center;
            margin-bottom: 30px;
            font-weight: 500;
            font-size: 28px;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }

        .form-group {
            margin-bottom: 25px;
            position: relative;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: var(--light-color);
            font-size: 14px;
            font-weight: 300;
        }

        .form-group input {
            width: 100%;
            padding: 12px 15px;
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 8px;
            color: var(--light-color);
            font-size: 16px;
            transition: var(--transition);
        }

        .form-group input:focus {
            outline: none;
            border-color: var(--accent-color);
            background: rgba(255, 255, 255, 0.15);
            box-shadow: 0 0 0 2px rgba(72, 149, 239, 0.2);
        }

        .login-btn {
            width: 100%;
            padding: 14px;
            background: var(--primary-color);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: var(--transition);
            margin-top: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }

        .login-btn:hover {
            background: var(--secondary-color);
            transform: translateY(-2px);
            box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
        }

        /* 控制界面 */
        .control-container {
            display: none;
            width: 100%;
            animation: fadeIn 0.5s ease-in-out;
        }

        .dashboard {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
        }

        .panel {
            background: rgba(26, 26, 46, 0.85);
            border-radius: 15px;
            padding: 20px;
            box-shadow: var(--shadow);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.15);
            transition: var(--transition);
            position: relative;
            overflow: hidden;
        }

        .panel::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 4px;
            background: var(--accent-color);
            transform: scaleX(0);
            transform-origin: left;
            transition: transform 0.4s ease;
        }

        .panel:hover::before {
            transform: scaleX(1);
        }

        .panel:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
        }

        .panel-title {
            color: var(--accent-color);
            margin-bottom: 15px;
            font-size: 18px;
            font-weight: 500;
            display: flex;
            align-items: center;
        }

        .panel-title i {
            margin-right: 10px;
            font-size: 20px;
        }

        .control-item {
            margin-bottom: 15px;
        }

        .control-label {
            display: block;
            margin-bottom: 8px;
            color: rgba(255, 255, 255, 0.7);
            font-size: 14px;
            font-weight: 300;
        }

        /* 实验室风格的开关控制 */
        .radio-group {
            display: flex;
            gap: 20px;
            margin-top: 10px;
        }
        
        .radio-item {
            display: flex;
            align-items: center;
            gap: 8px;
            position: relative;
        }
        
        .radio-item input[type="radio"] {
            width: 20px;
            height: 20px;
            cursor: pointer;
            accent-color: var(--accent-color);
            opacity: 0;
            position: absolute;
            left: 0;
            z-index: 2;
        }
        
        .radio-item label {
            cursor: pointer;
            font-size: 1.1rem;
            transition: all 0.3s;
            padding: 10px 20px;
            border-radius: 8px;
            background: rgba(0, 30, 70, 0.4);
            border: 1px solid rgba(100, 180, 255, 0.3);
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .radio-item input[type="radio"]:checked + label {
            background: rgba(72, 149, 239, 0.3);
            border-color: var(--accent-color);
            box-shadow: 0 0 10px rgba(72, 149, 239, 0.5);
        }
        
        .radio-item input[type="radio"]:checked + label.on {
            background: rgba(76, 201, 240, 0.2);
            border-color: var(--success-color);
        }
        
        .radio-item input[type="radio"]:checked + label.off {
            background: rgba(247, 37, 133, 0.2);
            border-color: var(--danger-color);
        }
        
        .radio-item label i {
            font-size: 18px;
        }
        
        .radio-item label.on i {
            color: var(--success-color);
        }
        
        .radio-item label.off i {
            color: var(--danger-color);
        }

        /* 状态指示器 */
        .status-indicator {
            display: inline-block;
            width: 10px;
            height: 10px;
            border-radius: 50%;
            margin-left: 8px;
        }
        
        .status-on {
            background: var(--success-color);
            box-shadow: 0 0 8px rgba(76, 201, 240, 0.8);
            animation: pulse 2s infinite;
        }
        
        .status-off {
            background: var(--danger-color);
            box-shadow: 0 0 8px rgba(247, 37, 133, 0.8);
        }

        @keyframes pulse {
            0% {
                box-shadow: 0 0 0 0 rgba(76, 201, 240, 0.8);
            }
            70% {
                box-shadow: 0 0 0 10px rgba(76, 201, 240, 0);
            }
            100% {
                box-shadow: 0 0 0 0 rgba(76, 201, 240, 0);
            }
        }

        /* 按钮样式 */
        .btn {
            padding: 10px 16px;
            border-radius: 8px;
            border: none;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: var(--transition);
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
        }

        .btn i {
            font-size: 18px;
        }

        .btn-primary {
            background: var(--primary-color);
            color: white;
        }

        .btn-primary:hover {
            background: var(--secondary-color);
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        }

        .btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none !important;
            box-shadow: none !important;
        }

        /* 数据展示 */
        .data-display {
            background: rgba(255, 255, 255, 0.1);
            border-radius: 10px;
            padding: 15px;
            margin-bottom: 15px;
            border: 1px solid rgba(255, 255, 255, 0.1);
            position: relative;
            overflow: hidden;
        }

        .data-display::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 4px;
            height: 100%;
            background: var(--accent-color);
        }

        .data-label {
            font-size: 12px;
            color: rgba(255, 255, 255, 0.6);
            margin-bottom: 5px;
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        .data-value {
            font-size: 24px;
            font-weight: 500;
            color: white;
            transition: all 0.3s ease;
        }

        .data-value.update {
            animation: flash 0.5s ease;
        }

        @keyframes flash {
            0% { color: var(--accent-color); }
            100% { color: white; }
        }

        .data-unit {
            font-size: 14px;
            color: rgba(255, 255, 255, 0.6);
            margin-left: 3px;
        }

        /* 地图和视频区域 */
        .map-container {
            grid-column: 1 / -1;
            height: 300px;
            background: rgba(0, 0, 0, 0.5);
            border-radius: 15px;
            overflow: hidden;
            position: relative;
            box-shadow: var(--shadow);
        }

        /* 地图样式 */
        #map {
            width: 100%;
            height: 100%;
            z-index: 1;
        }

        .map-overlay {
            position: absolute;
            bottom: 10px;
            left: 10px;
            background: rgba(0, 0, 0, 0.7);
            color: white;
            padding: 8px 15px;
            border-radius: 5px;
            font-size: 14px;
            z-index: 2;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .map-overlay i {
            color: var(--accent-color);
        }

        /* 全屏地图模式 */
        .map-fullscreen {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 10000;
            background: rgba(0, 0, 0, 0.9);
            display: none;
        }

        #fullscreen-map {
            width: 100%;
            height: 100%;
        }

        .map-controls {
            position: absolute;
            top: 20px;
            right: 20px;
            z-index: 10001;
            display: flex;
            gap: 10px;
        }

        .map-controls button {
            background: rgba(26, 26, 46, 0.8);
            color: white;
            border: none;
            padding: 8px 15px;
            border-radius: 5px;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 5px;
            transition: var(--transition);
        }

        .map-controls button:hover {
            background: var(--primary-color);
        }

        /* 视频区域 */
        .video-container {
            grid-column: 1 / -1;
            height: 300px;
            background: rgba(0, 0, 0, 0.5);
            border-radius: 15px;
            overflow: hidden;
            position: relative;
            box-shadow: var(--shadow);
            margin-top: 20px;
        }

        .video-feed {
            width: 100%;
            height: 100%;
            position: relative;
        }

        .camera-view {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .video-overlay {
            position: absolute;
            bottom: 10px;
            left: 10px;
            color: white;
            font-size: 16px;
            background: rgba(0, 0, 0, 0.5);
            padding: 5px 10px;
            border-radius: 4px;
            z-index: 2;
        }

        /* 状态提示 */
        .status-message {
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 15px 20px;
            border-radius: 8px;
            background: rgba(26, 26, 46, 0.95);
            color: white;
            box-shadow: var(--shadow);
            border-left: 4px solid var(--success-color);
            transform: translateX(120%);
            transition: transform 0.3s ease;
            z-index: 1000;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .status-message.error {
            border-left-color: var(--danger-color);
        }

        .status-message.warning {
            border-left-color: var(--warning-color);
        }

        .status-message.show {
            transform: translateX(0);
        }

        /* 加载动画 */
        .loader {
            display: inline-block;
            width: 16px;
            height: 16px;
            border: 3px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top-color: white;
            animation: spin 1s ease-in-out infinite;
        }

        @keyframes spin {
            to {
                transform: rotate(360deg);
            }
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .container {
                grid-template-columns: 1fr;
                padding: 10px;
            }

            .login-container {
                margin: 20% auto;
                padding: 30px;
            }

            .map-container {
                height: 200px;
            }

            .video-container {
                height: 200px;
            }
        }

        /* 图标字体 */
        .material-icons {
            font-size: 24px;
            vertical-align: middle;
        }

        /* 顶部导航 */
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px 20px;
            background: rgba(26, 26, 46, 0.8);
            backdrop-filter: blur(10px);
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 10px;
            font-size: 20px;
            font-weight: 500;
            color: var(--accent-color);
        }

        .user-info {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .logout-btn {
            background: rgba(247, 37, 133, 0.2);
            color: var(--light-color);
            border: none;
            padding: 8px 15px;
            border-radius: 5px;
            cursor: pointer;
            transition: var(--transition);
            display: flex;
            align-items: center;
            gap: 5px;
        }

        .logout-btn:hover {
            background: rgba(247, 37, 133, 0.3);
        }
        
        /* 济南主题元素 */
        .jn-theme {
            position: absolute;
            top: 20px;
            right: 20px;
            padding: 8px 15px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 20px;
            font-size: 14px;
            color: var(--accent-color);
            border: 1px solid var(--accent-color);
            z-index: 2;
            backdrop-filter: blur(4px);
        }
        .camera-btn-container {
            position: fixed;
            bottom: 30px;
            right: 30px;
            z-index: 1000;
        }
        
        .camera-btn {
            width: 60px;
            height: 60px;
            border-radius: 50%;
            background: var(--primary-color);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
            cursor: pointer;
            transition: var(--transition);
            border: 2px solid rgba(255, 255, 255, 0.3);
        }
        
        .camera-btn:hover {
            background: var(--secondary-color);
            transform: scale(1.1) translateY(-5px);
            box-shadow: 0 6px 15px rgba(0, 0, 0, 0.4);
        }
        
        .camera-btn i {
            font-size: 28px;
        }
        
        /* 摄像头视图样式 */
        .camera-view-container {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 80%;
            max-width: 800px;
            height: 70vh;
            background: rgba(26, 26, 46, 0.95);
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
            z-index: 10000;
            border: 2px solid var(--accent-color);
            overflow: hidden;
        }
        
        .camera-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px 20px;
            background: rgba(0, 0, 0, 0.7);
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .camera-title {
            color: var(--accent-color);
            font-size: 18px;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        
        .close-camera {
            background: rgba(247, 37, 133, 0.3);
            color: white;
            border: none;
            padding: 8px 15px;
            border-radius: 5px;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 5px;
            transition: var(--transition);
        }
        
        .close-camera:hover {
            background: rgba(247, 37, 133, 0.5);
        }
        
        .camera-frame {
            width: 100%;
            height: calc(100% - 60px);
            border: none;
        }
        
        .overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.8);
            z-index: 9999;
        }
        
        /* 控制面板美化 */
        .panel-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-top: 20px;
        }
        
        .simplified-control {
            display: flex;
            flex-direction: column;
            gap: 15px;
        }
        
        .control-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 10px;
        }
        
        .control-row .status-indicator {
            margin-right: 0;
        }
        
        .jn-landmark {
            position: absolute;
            bottom: 15px;
            right: 15px;
            padding: 6px 12px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 4px;
            font-size: 12px;
            color: var(--accent-color);
        }

        /* 优化布局 */
        .compact-panel {
            min-height: 220px;
        }
        .dashboard .panel {
            min-height: 220px;
        }
        .control-section {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
        }

        /* 实时数据更新指示器 */
        .update-indicator {
            position: absolute;
            top: 20px;
            left: 20px;
            font-size: 12px;
            color: var(--accent-color);
            background: rgba(0, 0, 0, 0.5);
            padding: 3px 8px;
            border-radius: 10px;
        }
        
        /* 系统状态指示器 */
        .system-status {
            position: fixed;
            bottom: 20px;
            left: 20px;
            background: rgba(26, 26, 46, 0.8);
            padding: 8px 15px;
            border-radius: 20px;
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 14px;
            z-index: 1000;
        }
        
        .status-dot {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background: var(--success-color);
            box-shadow: 0 0 8px var(--success-color);
            animation: pulse 2s infinite;
        }
        
        /* 新的数据面板样式 */
        .data-panel {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 15px;
        }
        
        .full-width {
            grid-column: 1 / -1;
        }
        
        .data-card {
            background: rgba(255, 255, 255, 0.05);
            border-radius: 10px;
            padding: 15px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        
        .data-card-title {
            font-size: 14px;
            color: var(--accent-color);
            margin-bottom: 10px;
            display: flex;
            align-items: center;
            gap: 5px;
        }
        
        .data-card-value {
            font-size: 28px;
            font-weight: 500;
            color: white;
        }
    </style>
</head>
<body>
    <!-- 登录界面 -->
    <div class="login-container" id="login-container">
        <h1><i class="material-icons">directions_car</i> 智能汽车控制系统</h1>
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" id="username" placeholder="请输入用户名" value="admin">
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" id="password" placeholder="请输入密码" value="admin">
        </div>
        <button class="login-btn" onclick="login()" id="login-btn">
            <i class="material-icons">login</i> 登录系统
        </button>
    </div>

    <!-- 控制界面 -->
    <div class="control-container" id="control-container">
        <!-- 顶部导航 -->
        <div class="header">
            <div class="logo">
                <i class="material-icons">directions_car</i>
                <span>智能汽车控制系统</span>
            </div>
            <div class="user-info">
                <span>管理员</span>
                <button class="logout-btn" onclick="logout()">
                    <i class="material-icons">logout</i> 退出
                </button>
            </div>
        </div>

        <div class="container">
            <!-- 济南主题标识 -->
            <div class="jn-theme">
                <i class="material-icons">location_on</i> 济南市 · 银荷大厦E座
            </div>

            <!-- 实时更新指示器 -->
            <div class="update-indicator" id="update-indicator">
                <i class="material-icons" style="font-size: 16px;">autorenew</i> 数据同步中...
            </div>
            
            <!-- 第一行：车辆状态 -->
            <div class="dashboard">
                <!-- 电池系统 -->
                <div class="panel compact-panel">
                    <h2 class="panel-title"><i class="material-icons">battery_charging_full</i> 电池系统</h2>
                    <div class="data-panel">
                        <div class="data-card">
                            <div class="data-card-title">
                                <i class="material-icons">bolt</i> 电池电压
                            </div>
                            <div class="data-card-value" id="battery-voltage">0.00<span class="data-unit">V</span></div>
                        </div>
                    </div>
                </div>

                <!-- 车速 -->
                <div class="panel compact-panel">
                    <h2 class="panel-title"><i class="material-icons">speed</i> 车速</h2>
                    <div class="data-panel">
                        <div class="data-card full-width">
                            <div class="data-card-title">
                                <i class="material-icons">speed</i> 当前车速
                            </div>
                            <div class="data-card-value" id="speed-value">0<span class="data-unit">km/h</span></div>
                        </div>
                    </div>
                </div>
                
                <!-- 环境监测 -->
                <div class="panel compact-panel">
                    <h2 class="panel-title"><i class="material-icons">device_thermostat</i> 环境监测</h2>
                    <div class="data-panel">
                        <div class="data-card">
                            <div class="data-card-title">
                                <i class="material-icons">thermostat</i> 车内温度
                            </div>
                            <div class="data-card-value" id="temp-value">0.0<span class="data-unit">℃</span></div>
                        </div>
                        <div class="data-card">
                            <div class="data-card-title">
                                <i class="material-icons">water_drop</i> 车内湿度
                            </div>
                            <div class="data-card-value" id="humidity-value">0.0<span class="data-unit">%</span></div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 第二行：控制面板 -->
            <div class="control-section">
                <!-- 车门控制 -->
                <div class="panel compact-panel">
                    <h2 class="panel-title"><i class="material-icons">directions_car</i> 车门控制</h2>
                    <div class="control-group">
                        <div class="control-item">
                            <div class="control-label">
                                <i class="material-icons">door_front</i>
                                <span>车门状态</span>
                                <span class="status-indicator status-off" id="door-status"></span>
                            </div>
                            <div class="radio-group">
                                <div class="radio-item">
                                    <input type="radio" name="door" id="door_on" onclick="door('on')">
                                    <label for="door_on" class="on"><i class="material-icons">lock_open</i> 开启</label>
                                </div>
                                <div class="radio-item">
                                    <input type="radio" name="door" id="door_off" onclick="door('off')" checked>
                                    <label for="door_off" class="off"><i class="material-icons">lock</i> 关闭</label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 空调系统 -->
                <div class="panel compact-panel">
                    <h2 class="panel-title"><i class="material-icons">ac_unit</i> 空调系统</h2>
                    <div class="control-group">
                        <div class="control-item">
                            <div class="control-label">
                                <i class="material-icons">thermostat</i>
                                <span>空调状态</span>
                                <span class="status-indicator status-off" id="ac-status"></span>
                            </div>
                            <div class="radio-group">
                                <div class="radio-item">
                                    <input type="radio" name="ac" id="ac_on" onclick="ac('on')">
                                    <label for="ac_on" class="on"><i class="material-icons">power_settings_new</i> 开启</label>
                                </div>
                                <div class="radio-item">
                                    <input type="radio" name="ac" id="ac_off" onclick="ac('off')" checked>
                                    <label for="ac_off" class="off"><i class="material-icons">power_settings_new</i> 关闭</label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 第三行：座椅和方向盘控制 -->
            <div class="control-section">
                <!-- 座椅按摩控制 -->
                <div class="panel compact-panel">
                    <h2 class="panel-title"><i class="material-icons">airline_seat_recline_normal</i> 座椅按摩</h2>
                    <div class="control-group">
                        <div class="control-item">
                            <div class="control-label">
                                <i class="material-icons">massage</i>
                                <span>按摩状态</span>
                                <span class="status-indicator status-off" id="massage-status"></span>
                            </div>
                            <div class="radio-group">
                                <div class="radio-item">
                                    <input type="radio" name="massage" id="massage_on" onclick="massage('on')">
                                    <label for="massage_on" class="on"><i class="material-icons">power_settings_new</i> 开启</label>
                                </div>
                                <div class="radio-item">
                                    <input type="radio" name="massage" id="massage_off" onclick="massage('off')" checked>
                                    <label for="massage_off" class="off"><i class="material-icons">power_settings_new</i> 关闭</label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 方向盘加热控制 -->
                <div class="panel compact-panel">
                    <h2 class="panel-title"><i class="material-icons">heat</i> 方向盘加热</h2>
                    <div class="control-group">
                        <div class="control-item">
                            <div class="control-label">
                                <i class="material-icons">heat</i>
                                <span>加热状态</span>
                                <span class="status-indicator status-off" id="wheel-heat-status"></span>
                            </div>
                            <div class="radio-group">
                                <div class="radio-item">
                                    <input type="radio" name="wheel-heat" id="wheel_heat_on" onclick="wheelHeat('on')">
                                    <label for="wheel_heat_on" class="on"><i class="material-icons">power_settings_new</i> 开启</label>
                                </div>
                                <div class="radio-item">
                                    <input type="radio" name="wheel-heat" id="wheel_heat_off" onclick="wheelHeat('off')" checked>
                                    <label for="wheel_heat_off" class="off"><i class="material-icons">power_settings_new</i> 关闭</label>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 地图区域 -->
            <div class="map-container">
                <div id="map"></div>
                <div class="map-overlay">
                    <i class="material-icons">location_on</i>
                    <span id="location-text">当前位置：济南市银荷大厦E座</span>
                </div>
                <div class="jn-landmark">
                    <i class="material-icons">place</i> 济南市 · 历下区
                </div>
            </div>
        </div>
    </div>
    
    <!-- 系统状态指示器 -->
    <div class="system-status" id="system-status">
        <div class="status-dot"></div>
        <span>系统运行中</span>
    </div>
    
    <div class="camera-btn-container">
        <div class="camera-btn" id="camera-btn">
            <i class="material-icons">videocam</i>
        </div>
    </div>
    <div class="overlay" id="camera-overlay"></div>
    <div class="camera-view-container" id="camera-view">
        <div class="camera-header">
            <div class="camera-title">
                <i class="material-icons">videocam</i>
                <span>车载摄像头 - 实时监控</span>
            </div>
            <button class="close-camera" onclick="closeCamera()">
                <i class="material-icons">close</i> 关闭
            </button>
        </div>
        <iframe class="camera-frame" id="camera-frame" src="about:blank"></iframe>
    </div>

    <!-- 全屏地图 -->
    <div class="map-fullscreen" id="map-fullscreen">
        <div id="fullscreen-map"></div>
        <div class="map-controls">
            <button onclick="exitFullscreenMap()">
                <i class="material-icons">close</i> 退出
            </button>
            <button onclick="centerOnVehicle()">
                <i class="material-icons">gps_fixed</i> 定位车辆
            </button>
        </div>
    </div>

    <!-- 状态提示 -->
    <div class="status-message" id="status-message">
        <i class="material-icons">check_circle</i>
        <span>操作成功！</span>
    </div>
    
    <!-- 引入Leaflet库 -->
    <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
    <script>
        // 服务器API端点
        const API_BASE_URL = '/'; 
        const DATA_FETCH_INTERVAL = 2000; // 数据刷新间隔(毫秒)
        let dataFetchInterval; // 定时器ID
        
        // 控制键值映射 - 使用第一个文件中的键值
        const CONTROL_KEYS = {
            door: 304,
            ac: 303,
            massage: 104,
            wheelHeat: 102
        };
        
        // 当前状态
        let currentState = {
            door: false,
            ac: false,
            massage: false,
            wheelHeat: false
        };
        
        // 地图变量
        let map;
        let vehicleMarker;
        
        // 设备控制函数 - 使用第一个文件中的格式
        function door(obj) {
            const key = CONTROL_KEYS.door;
            const xhr = new XMLHttpRequest();
            const url = API_BASE_URL;
            
            xhr.open("POST", url, true);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4) {
                    if (xhr.status == 200) {
                        console.log("响应内容:", xhr.responseText);
                    } else {
                        showStatusMessage("操作失败: " + xhr.statusText, true);
                    }
                }
            };
            
            let o;
            if (obj == 'on') {
                document.getElementById('door-status').className = 'status-indicator status-on';
                o = 1;
                showStatusMessage("车门已开启");
            } else if (obj == 'off') {
                document.getElementById('door-status').className = 'status-indicator status-off';
                o = 0;
                showStatusMessage("车门已关闭");
            }
            
            // 使用第一个文件中的格式：key=xxxo=1
            xhr.send("key=" + key + "o=" + o);
        }
        
        function ac(obj) {
            const key = CONTROL_KEYS.ac;
            const xhr = new XMLHttpRequest();
            const url = API_BASE_URL;
            
            xhr.open("POST", url, true);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4) {
                    if (xhr.status == 200) {
                        console.log("响应内容:", xhr.responseText);
                    } else {
                        showStatusMessage("操作失败: " + xhr.statusText, true);
                    }
                }
            };
            
            let o;
            if (obj == 'on') {
                document.getElementById('ac-status').className = 'status-indicator status-on';
                o = 1;
                showStatusMessage("空调已开启");
            } else if (obj == 'off') {
                document.getElementById('ac-status').className = 'status-indicator status-off';
                o = 0;
                showStatusMessage("空调已关闭");
            }
            
            // 使用第一个文件中的格式：key=xxxo=1
            xhr.send("key=" + key + "o=" + o);
        }
        
        function massage(obj) {
            const key = CONTROL_KEYS.massage;
            const xhr = new XMLHttpRequest();
            const url = API_BASE_URL;
            
            xhr.open("POST", url, true);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4) {
                    if (xhr.status == 200) {
                        console.log("响应内容:", xhr.responseText);
                    } else {
                        showStatusMessage("操作失败: " + xhr.statusText, true);
                    }
                }
            };
            
            let o;
            if (obj == 'on') {
                document.getElementById('massage-status').className = 'status-indicator status-on';
                o = 1;
                showStatusMessage("座椅按摩已开启");
            } else if (obj == 'off') {
                document.getElementById('massage-status').className = 'status-indicator status-off';
                o = 0;
                showStatusMessage("座椅按摩已关闭");
            }
            
            // 使用第一个文件中的格式：key=xxxo=1
            xhr.send("key=" + key + "o=" + o);
        }
        
        function wheelHeat(obj) {
            const key = CONTROL_KEYS.wheelHeat;
            const xhr = new XMLHttpRequest();
            const url = API_BASE_URL;
            
            xhr.open("POST", url, true);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4) {
                    if (xhr.status == 200) {
                        console.log("响应内容:", xhr.responseText);
                    } else {
                        showStatusMessage("操作失败: " + xhr.statusText, true);
                    }
                }
            };
            
            let o;
            if (obj == 'on') {
                document.getElementById('wheel-heat-status').className = 'status-indicator status-on';
                o = 1;
                showStatusMessage("方向盘加热已开启");
            } else if (obj == 'off') {
                document.getElementById('wheel-heat-status').className = 'status-indicator status-off';
                o = 0;
                showStatusMessage("方向盘加热已关闭");
            }
            
            // 使用第一个文件中的格式：key=xxxo=1
            xhr.send("key=" + key + "o=" + o);
        }

        // 显示状态消息
        function showStatusMessage(message, isError = false) {
            const statusMessage = document.getElementById('status-message');
            const icon = statusMessage.querySelector('i');
            const text = statusMessage.querySelector('span');
            
            text.textContent = message;
            statusMessage.className = 'status-message';
            
            if (isError) {
                statusMessage.classList.add('error');
                icon.textContent = 'error';
            } else {
                icon.textContent = 'check_circle';
            }
            
            statusMessage.classList.add('show');
            
            setTimeout(() => {
                statusMessage.classList.remove('show');
            }, 3000);
        }

        // 打开摄像头流
        function openCameraStream() {
            const hostname = window.location.hostname;
            const videoStreamUrl = `http://${hostname}:8080/stream.html`;
            document.getElementById('camera-frame').src = videoStreamUrl;
            document.getElementById('camera-overlay').style.display = 'block';
            document.getElementById('camera-view').style.display = 'block';
            showStatusMessage('正在打开车载摄像头监控...');
        }

        // 关闭摄像头视图
        function closeCamera() {
            document.getElementById('camera-overlay').style.display = 'none';
            document.getElementById('camera-view').style.display = 'none';
            document.getElementById('camera-frame').src = 'about:blank';
        }

        // 登录功能
        async function login() {
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            const loginBtn = document.getElementById('login-btn');
            
            loginBtn.innerHTML = '<div class="loader"></div> 登录中...';
            loginBtn.disabled = true;
            
            try {
                await new Promise(resolve => setTimeout(resolve, 1500));
                
                if (!username || !password) {
                    throw new Error('请输入用户名和密码');
                }
                
                if (username === 'admin' && password === 'admin') {
                    document.getElementById('login-container').style.display = 'none';
                    document.getElementById('control-container').style.display = 'block';
                    showStatusMessage('登录成功！欢迎使用智能汽车控制系统');
                    // 登录成功后开始获取真实数据
                    startDataFetching();
                } else {
                    throw new Error('用户名或密码错误');
                }
            } catch (error) {
                console.error('登录失败:', error);
                showStatusMessage(`登录失败: ${error.message}`, true);
            } finally {
                loginBtn.innerHTML = '<i class="material-icons">login</i> 登录系统';
                loginBtn.disabled = false;
            }
        }

        // 退出功能
        function logout() {
            document.getElementById('control-container').style.display = 'none';
            document.getElementById('login-container').style.display = 'block';
            closeCamera();
            showStatusMessage('您已成功退出系统');
            stopDataFetching();
        }

        // 初始化地图
        function initMap() {
            map = L.map('map', {
                zoomControl: false,
                attributionControl: false
            }).setView([36.668329, 117.126031], 17);
            
            L.tileLayer('https://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}', {
                subdomains: ['1', '2', '3', '4'],
                maxZoom: 19
            }).addTo(map);
            
            const vehicleIcon = L.divIcon({
                className: 'vehicle-icon',
                html: '<div class="vehicle-marker"><i class="material-icons" style="color:#4895ef; font-size:32px;">directions_car</i></div>',
                iconSize: [40, 40],
                iconAnchor: [20, 20]
            });
            
            vehicleMarker = L.marker([36.668329, 117.126031], {
                icon: vehicleIcon,
                zIndexOffset: 1000
            }).addTo(map);
            
            map.on('click', function(e) {
                openFullscreenMap();
            });
        }
        
        // 打开全屏地图
        function openFullscreenMap() {
            document.getElementById('map-fullscreen').style.display = 'block';
            const fullscreenMap = L.map('fullscreen-map').setView(vehicleMarker.getLatLng(), 17);
            
            L.tileLayer('https://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}', {
                subdomains: ['1', '2', '3', '4'],
                maxZoom: 19
            }).addTo(fullscreenMap);
            
            L.marker(vehicleMarker.getLatLng(), {
                icon: vehicleMarker.options.icon,
                zIndexOffset: 1000
            }).addTo(fullscreenMap);
        }
        
        // 退出全屏地图
        function exitFullscreenMap() {
            document.getElementById('map-fullscreen').style.display = 'none';
        }
        
        // 定位车辆
        function centerOnVehicle() {
            const fullscreenMap = document.getElementById('fullscreen-map')._leaflet_map;
            if (fullscreenMap) {
                fullscreenMap.setView(vehicleMarker.getLatLng(), 17);
            }
        }

        // 获取数据的函数
        function fetchData(key) {
            return new Promise((resolve, reject) => {
                const xhr = new XMLHttpRequest();
                const url = API_BASE_URL;
                
                xhr.open('POST', url, true);
                xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                
                xhr.onreadystatechange = function() {
                    if (xhr.readyState === 4) {
                        if (xhr.status === 200) {
                            resolve(xhr.responseText.trim());
                        } else {
                            reject(new Error(`请求失败: ${xhr.statusText}`));
                        }
                    }
                };
                
                xhr.onerror = function() {
                    reject(new Error('网络错误'));
                };
                
                xhr.send(`input=${key}`);
            });
        }
        
        // 更新所有数据
        async function updateAllData() {
            const indicator = document.getElementById('update-indicator');
            indicator.style.display = 'block';
            
            try {
                // 使用第一个文件中的键值定义
                const DATA_KEYS = {
                    batteryVoltage: 101,   // 电池电压key
                    speed: 103,             // 车速key
                    temperature: 301,       // 温度key
                    humidity: 302          // 湿度key
                };
                
                const [batteryVoltage, speed, temperature, humidity] = await Promise.all([
                    fetchData(DATA_KEYS.batteryVoltage),
                    fetchData(DATA_KEYS.speed),
                    fetchData(DATA_KEYS.temperature),
                    fetchData(DATA_KEYS.humidity)
                ]);
                
                // 更新电池电压
                if (batteryVoltage && !isNaN(parseFloat(batteryVoltage))) {
                    updateDataDisplay('battery-voltage', parseFloat(batteryVoltage).toFixed(2), 'V');
                } else {
                    updateDataDisplay('battery-voltage', "0.00", 'V');
                }
                
                // 更新车速
                if (speed && !isNaN(parseInt(speed))) {
                    updateDataDisplay('speed-value', speed, 'km/h');
                } else {
                    updateDataDisplay('speed-value', "0", 'km/h');
                }
                
                // 更新温度
                if (temperature && !isNaN(parseFloat(temperature))) {
                    updateDataDisplay('temp-value', parseFloat(temperature).toFixed(1), '℃');
                } else {
                    updateDataDisplay('temp-value', "0.0", '℃');
                }
                
                // 更新湿度
                if (humidity && !isNaN(parseFloat(humidity))) {
                    updateDataDisplay('humidity-value', parseFloat(humidity).toFixed(1), '%');
                } else {
                    updateDataDisplay('humidity-value', "0.0", '%');
                }
                
            } catch (error) {
                console.error('更新数据失败:', error);
                // 更新失败时显示0值
                updateDataDisplay('battery-voltage', "0.00", 'V');
                updateDataDisplay('speed-value', "0", 'km/h');
                updateDataDisplay('temp-value', "0.0", '℃');
                updateDataDisplay('humidity-value', "0.0", '%');
            } finally {
                indicator.style.display = 'none';
            }
        }
        
        // 更新数据显示
        function updateDataDisplay(elementId, value, unit) {
            const element = document.getElementById(elementId);
            if (element) {
                element.innerHTML = `${value}<span class="data-unit">${unit}</span>`;
            }
        }
        
        // 开始定时获取数据
        function startDataFetching() {
            // 立即获取一次数据
            updateAllData();
            
            // 设置定时器定期获取数据
            if (!dataFetchInterval) {
                dataFetchInterval = setInterval(updateAllData, DATA_FETCH_INTERVAL);
            }
        }
        
        // 停止定时获取数据
        function stopDataFetching() {
            if (dataFetchInterval) {
                clearInterval(dataFetchInterval);
                dataFetchInterval = null;
            }
        }

        // 页面加载完成后初始化
        document.addEventListener('DOMContentLoaded', function() {
            document.getElementById('camera-btn').addEventListener('click', openCameraStream);
            initMap();
            
            // 移除模拟随机数据更新的代码
            // 不再有模拟数据更新
        });
    </script>
</body>
</html>